package cn.com.dycc.util;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import cn.com.dycc.sys_manage.deptsysmanagement.entity.Dept;

public class LayDeptTreeUtil {
	
	public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();
	public List<Dept> deptCommon;
	public List<Object> list = new ArrayList<Object>(); 
	
	public List<Object> PartyList(List<Dept> dept){ 
		this.deptCommon = dept;
		for(Dept x : dept){
			Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
			if("0".equals(x.getPid())){
				mapArr.put("id",x.getDept_no());
				mapArr.put("name",x.getDept_name());
//				mapArr.put("pid",x.getPid());
				mapArr.put("spread","true");
				//子部门
				mapArr.put("children",children(x.getDept_no()));
				list.add(mapArr);
			}
		}
		return list;
	}
	
	 public List<?> children(String deptNo){
		 List<Object> lists = new ArrayList<Object>();
		 for(Dept a:deptCommon){
			 Map<String,Object> childArray = new LinkedHashMap<String, Object>();
			 if(deptNo.equals(a.getPid())){
				 childArray.put("id",a.getDept_no());
				 childArray.put("name",a.getDept_name());
//				 childArray.put("pid",a.getPid());
				 childArray.put("spread","true");
				//子部门
				 childArray.put("children",children(a.getDept_no())); 
				 lists.add(childArray);
			 }
		 }
		 return lists;
	 }
}
